/**
 * com.monte.persistence.command.BatchUpdateEntityCommand.java
 * create by FengMy from 2013
 */
package com.monte.persistence.command;

import java.util.List;

import com.monte.persistence.CommandContext;
import com.monte.persistence.PersistenceCommand;

/**
 * @描述:批量更新实体命令
 * @author FengMy
 * @since 2013-3-4
 */
public class BatchUpdateEntityCommand<T> implements PersistenceCommand {
	
	private List<T> entities;
	
	public BatchUpdateEntityCommand(List<T> entities){
		this.entities = entities;
	}

	@Override
	public Object execute(CommandContext context) {
		if(entities != null && entities.size() > 0){
			for(T entity : entities){
				context.getEntityManager().merge(entity);
			}
			return entities.size();
		}
		return 0;
	}

}
